package com.netty.server.processor.down;

import com.netty.server.cmd.ByteCmd;
import com.netty.server.cmd.Header;
import com.netty.server.sender.CmdRequest;

/**
 * @author: 王霄
 * @date: 2022/2/18 19:30
 */
public abstract class DefaultDownPlugin implements DownPlugin {

    protected abstract byte[] serializer(BaseData data);

    @Override
    public ByteCmd handler(CmdRequest request) {
        return ByteCmd.builder()
                .header(Header.SERVICE)
                .cmdType(getCmd())
                .cmdId(request.getCmdId())
                .needAck(request.isNeedAck())
                .body(serializer(request.getData()))
                .build();
    }
}
